<template>
    <div class="school">
        <h2>学校名称：{{ name }}</h2>
        <h2>学校地址{{ address }}</h2>
    </div>
</template>

<script>
import pubsub from "pubsub-js";
export default {
    name: "StudentInfo",
    data() {
        return {
            name: "往生堂",
            address: "璃月",
        };
    },
    methods: {
        msg(msgName, data) {
            console.log(
                "有人发布了hello消息,hello消息的回调执行了",
                msgName,
                data
            );
        },
    },
    mounted() {
        this.pubId = pubsub.subscribe("hello", this.msg);
    },
    beforeDestroy() {
        pubsub.unsubscribe(this.pubId);
    },
};
</script>

<style scoped>
.school {
    padding: 5px;
    background-color: rgb(143, 200, 253);
    margin-bottom: 20px;
}
</style>